// import './assets/main.css'

import { createApp } from 'vue';
import App from './App.vue';

// 引入路由
import Router from '@/routers/index';

// 引入Vant UI
import Vant from 'vant';
// 引入组件样式
import 'vant/lib/index.css';

// 引入封装的请求
import Http from '@/services/request';

// 引入Pinia
import { createPinia } from 'pinia';
// 引入pinia数据持久化插件
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';

// 引入自定义状态管理
import Stores from '@/stores/stores';

const app = createApp(App)
    .use(Router)
    .use(Vant)
    .use(createPinia().use(piniaPluginPersistedstate))
    .use(Stores)
    .use(Http)
    .mount('#app');

Router.beforeEach(async (to, from) => {

    let IsLogin = to.meta?.IsLogin === true ? true : false;

    if(IsLogin === false)
    {
        return true;
    }

    let { id, mobile } = app.$business.value;
    
    let result = await app.$http.post('/business/check',{id, mobile});

    if(result.code === 0)
    {
        // 重置缓存
        app.$store.$BusinessReset();

        return {path: '/business/login'};
    }

    return true;
});